package auctionhausen



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Bid)
class BidUnitTests {

	static final def EMAILS = [valid : 'test@test.edu']
	static final def PASSWORDS = [valid : '123456']
	static final def BIDS = [
		blank: '', zero : 0.00, negative : -5.25,
		positive : 5.25 ]
	
	// B-1: Bids have the following required fields: amount and date/time of bid (unit test)
	// B-2: Bids are required to be for a Listing (unit test)
	// B-3: Bids are required to have a bidder (Customer) (unit test)
	void testRequiredFields() {

		def bid = new Bid()

		assert !bid.validate()
		assert 'nullable' == bid.errors['amount'].code
		assert 'nullable' == bid.errors['bidder'].code
		assert 'nullable' == bid.errors['listing'].code
		
		// Note that since we're using dateCreated for the date/time of the bid,
		// we will always have that field set even when we don't specify it.
		bid.save(flush : true)
		assertNull bid.errors['dateCreated']
	}
}